Ext.define('TS.controller.PeriodEndForwards', {
    extend: 'Ext.app.Controller',
    models: ['TS.model.common.PeriodModel'],
    views: [
        'settings.PeriodEndForward'
    ],
    init: function() {
        this.control({ 
        	'periodendforward button[action=forward]':{
        		click: this.onForward
        	}
        });
    },
    onForward:function(button) {
    	var form = button.up();
		var begYear = form.query('numberfield[name=begYear]')[0];
		var begPeriod = form.query('numberfield[name=begPeriod]')[0];
		var endYear = form.query('numberfield[name=endYear]')[0];
		var endPeriod = form.query('numberfield[name=endPeriod]')[0];
    	
		var begin = begYear.getValue() + begPeriod.getValue()/100;
		var end = endYear.getValue() + endPeriod.getValue()/100;
		if(end <= begin) {
			Ext.Msg.show({
				title:'警告',
				msg:'下一期间[' + begin + ']必须大于当前期间[' + end + ']',
				buttons:Ext.Msg.OK,
				icon:Ext.Msg.WARNING
			});
			return false;
		}
		Ext.Msg.confirm('结转','真的要执行结转吗?结转前请确认数据全部准确无误!!!',function(b){
				if(b=='yes'){
					Ext.Msg.show({
						msg:'正在进行期末结转，请稍候...',
						progressText: 'Processing...',
			            wait:true,
			            waitConfig: {interval:200}
					});
					//Ext.getBody().mask('正在进行期末结转，请稍候...');
					
					Ext.Ajax.request({
						url:'periodendforward/periodForward.do',
						params:{curYear:begYear.getValue(),curPeriod:begPeriod.getValue(),nextYear:endYear.getValue(),nextPeriod:endPeriod.getValue()},
						timeout:600000,
						success:function(response){
							var res = Ext.decode(response.responseText);
							Ext.MessageBox.hide();
							Ext.Msg.show({
								title:'ThinkGSP',
								msg:res.msg,
								buttons:Ext.Msg.OK,
								icon:Ext.Msg.INFO
							});
						},
						failure:function(response) {
							var res = Ext.decode(response.responseText);
							Ext.MessageBox.hide();
							Ext.Msg.show({
								title:'错误',
								msg:res.msg,
								buttons:Ext.Msg.OK,
								icon:Ext.Msg.ERROR
							});
						}
					});
				}
		});		
    }
});